<%@ include file="/WEB-INF/jsp/common/include.jsp" %>
<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib prefix="app" uri="AppTags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<tiles:insertDefinition name="manageLayout.tiles">
  <tiles:putAttribute name="pageTitle">Хату.бы - Просмотр моего объявления</tiles:putAttribute>
  <tiles:putAttribute name="statisticsTab" value="selected" cascade="true"/>
  <tiles:putAttribute name="manageBody" cascade="true">
    <div>
      <div class="box white-box">
        <div class="box-container">
          <p>
            За последние сутки ваше объявление было показано
            <span id="lastDayViewStatistics"><c:choose><c:when test="${empty flatAd}">0</c:when><c:otherwise>&nbsp;</c:otherwise></c:choose></span>
            раз.
          </p>
          <script type="text/javascript" src="https://www.google.com/jsapi"></script>
          <script type="text/javascript">
            google.load("visualization", "1", {packages:["corechart"]});
            google.setOnLoadCallback(drawViewStatisticsChart);
            function drawViewStatisticsChart() {
              var data = new google.visualization.DataTable();
              data.addColumn('string', 'Дата');
              data.addColumn('number', 'Показы');

              var chart = new google.visualization.ColumnChart(document.getElementById('viewStatisticsChart'));
              var jsonData = $.ajax({
                url: "/ad/manage/statistics/proxy.do?flatAdId=${flatAd.id}",
                dataType:"json",
                async: false
              }).responseText;
              var json = JSON.parse(jsonData);
              var lastDayViewStatistics = 0;
              if(json && json.length > 0){
                lastDayViewStatistics = json[json.length - 1][1]
              }
              $('#lastDayViewStatistics').text(lastDayViewStatistics);
              data.addRows(json);
              chart.draw(data, {width: 500, height: 240, title: 'Количество показов по дням',
                hAxis: {title: 'Дата', titleTextStyle: {color: 'red'}}
              });
            }
          </script>
          <div id="viewStatisticsChart"></div>
        </div>
      </div>
      <jsp:include page="/WEB-INF/jsp/ad/manage/ratingEditor/view.jsp"/>
    </div>
  </tiles:putAttribute>
</tiles:insertDefinition>